import java.util.Scanner;

public class Demo {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();

        String[] str1 = str.split(" ");
        int year = Integer.valueOf(str1[0]);
        boolean fly = false;
        if((year % 4 == 0 && year % 100 != 0 )||( year % 400 == 0)) {
            fly = true;
        }

        int num = Integer.valueOf(str1[2]);
        int time = Integer.valueOf(str1[1]);
        switch(time) {
            case 12:
                if(time != 12) {
                    num += 31;
                }
            case 11:
                if(time != 11) {
                    num += 30;
                }
            case 10:
                if(time != 10) {
                    num += 31;
                }
            case 9:
                if(time != 9) {
                    num += 30;
                }
            case 8:
                if(time != 8) {
                    num += 31;
                }
            case 7:
                if(time != 7) {
                    num += 31;
                }
            case 6:
                if(time != 6) {
                    num += 30;
                }
            case 5:
                if(time != 5) {
                    num += 31;
                }
            case 4:
                if(time != 4) {
                    num += 30;
                }
            case 3:
                if(time != 3) {
                    num += 31;
                }
            case 2:
                if(time != 2 && fly) {
                    num += 29;
                }else if(time != 2 && !fly){
                    num += 28;
                }
            case 1:
                if(time != 1) {
                    num += 31;
                }
        }

        System.out.println(num);
    }
}
